package cn.xiaobai.service.impl.impl;

import cn.xiaobai.domain.DayResult;
import cn.xiaobai.enums.StateEnum;
import cn.xiaobai.service.DateAnalyzeService;
import cn.xiaobai.service.HolidayAnalyzeService;
import cn.xioabai.common.domain.ResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

/**
 * @Author yangdaji
 * @Date 2023/8/13
 * @PackageName cn.xiaobai.service.impl
 * @ClassName HolidayAnalyzeServiceImpl
 */
@Slf4j
@Service
public class HolidayAnalyzeServiceImpl implements HolidayAnalyzeService {

    @Autowired
    private DateAnalyzeService dateAnalyzeService;

    @Override
    public Integer queryDateHoliday(String day) {
        return dateAnalyzeService.queryDateHoliday(day);
    }

    @Override
    public List<DayResult> queryMultiDateHoliday(List<String> days) {

        final List<DayResult> multiDateList = new LinkedList<>();
        if (CollectionUtils.isNotEmpty(days)) {
            days.stream()
                    .filter(Objects::nonNull)
                    .distinct().forEach(day -> {
                        Integer state = queryDateHoliday(day);
                        ResultDTO<Integer> success = ResultDTO.success(StateEnum.getExplain(state), state);
                        multiDateList.add(new DayResult(day).convert(success));
                    });
        }
        return multiDateList;
    }
}
